import Vue from 'vue'
import VueRouter from 'vue-router'
import IndexLayout from '../layout/IndexLayout.vue'
import None from "@/views/My/None";
// import {getPersonalInformation} from "@/api/login-aip";

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const routes = [
    {
        path: '/',
        name: 'IndexLayout',
        component: IndexLayout,
        children: [
            //  首页
            {
                path: '',
                name: 'IndexPage',
                //  路由懒加载
                component: () => import("../views/Index/IndexPage.vue")
            },
            //  我的页面
            {
                path: '/MyPage',
                name: 'MyPage',
                meta: {
                    //  是否登录
                    isLogin: true
                },
                component: () => import("../views/My/MyPage.vue")
            },
            //   未登录
            {
                path: '/NotLogged',
                name: 'NotLogged',
                component: () => import("../views/My/NotLogged.vue")
            },
            //   歌曲MV
            {
                path: '/MVPage',
                name: 'MVPage',
                component: () => import("../views/MV/MVPage.vue")
            },
            //    空页面
            {
                path: '/None',
                name: 'None',
                component: None
            },
            //搜索
            {
                path: '/SearchPage',
                name: 'SearchPage',
                //  路由懒加载
                component: () => import("../views/Search/SearchPage.vue")
            },
        ]
    },
    //  登录
    {
        path: '/MyLogin',
        name: 'MyLogin',
        component: () => import("../views/My/MyLogin.vue")
    },
    //  注册
    {
        path: '/Registered',
        name: 'Registered',
        component: () => import("../views/My/Registered")
    },
    //  个人信息
    {
        path: '/PersonalInformation',
        name: 'PersonalInformation',
        component: () => import("../views/My/PersonalInformation.vue")
    },
    //  修改个人信息
    {
        path: '/EditData',
        name: 'EditData',
        component: () => import("../views/My/EditData.vue")
    },


    //新闻详情页
    {
        path: '/NewDetails',
        name: 'NewDetails',
        //  路由懒加载
        component: () => import("../components/NewDetails.vue")
    },

    //  忘记密码
    {
        path: '/ForgotPassword',
        name: 'ForgotPassword',
        component: () => import("../views/My/ForgotPassword.vue")
    },

    //    MV详情
    {
        path: '/MVComments',
        name: 'MVComments',
        component: () => import("../views/MV/components/MVComments")
    }
]


const router = new VueRouter({
    routes
})

//  to      去哪个页面
//  from    在那个页面
//  next()
//      next()      可以跳转
//      next(false) 不能跳转
//      next()


// router.beforeEach((to, from, next) => {
//     if (to.meta.isLogin) {
//         getPersonalInformation().then(res => {
//             // console.log(res)
//             if (res.code !== 0) {
//                 next("/NotLogged")
//             } else {
//                 next()
//             }
//         })
//     } else {
//         next()
//     }
// })


export default router
